package com.itheima.info.manger.system.controller;

import com.itheima.info.manger.system.domain.Teacher;
import com.itheima.info.manger.system.service.TeacherService;

import java.util.Scanner;

public class TeacherController {

    public void start() {
        Scanner sc = new Scanner(System.in);
        loop:
        while (true) {
            System.out.println("--------欢迎来到 <老师> 管理系统--------");
            System.out.println("请输入您的选择: 1.添加老师  2.删除老师  3.修改老师  4.查看老师  5.退出老师系统");

            String choice = sc.next();
            switch (choice) {
                case "1":
                    System.out.println("新增老师");
                    break;
                case "2":
                    System.out.println("删除老师");
                    break;
                case "3":
                    System.out.println("修改老师");
                    break;
                case "4":
                    System.out.println("查看老师");
                    break;
                case "5":
                    //break loop;
                    return;

                default:
                    System.out.println("输入有误");
                    break;
            }
        }
    }


    public void addTeacher() {
        TeacherService teacherService = new TeacherService();
        //组织老师对象
        Scanner sc = new Scanner(System.in);
        String sid=null;
        while (true){
            System.out.println("请输入工号");
            sid = sc.next();
            boolean exist = teacherService.isExist(sid);
            if(exist){
                System.out.println("已经存在请重新输入");
            }else {
                break;
            }
        }
        System.out.println("请输入姓名");
        String name = sc.next();
        System.out.println("请输入年龄");
        int age= sc.nextInt();
        System.out.println("请输入生日");
        String birthday = sc.next();
        Teacher teacher = new Teacher(sid,name,age,birthday);


        boolean b = teacherService.addTeacher(teacher);
        if(b){
            System.out.println("新增成功");
        }else {
            System.out.println("新增失败");
        }

    }

}
